package com.itheima.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itheima.dao.UserMapper;
import com.itheima.model.domain.Article;
import com.itheima.model.domain.Statistic;
import com.itheima.model.domain.User;
import com.itheima.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author chenxiangxi
 * @create 2023/6/5 22:05
 */

@Service
public class UserServiceImpl implements IUserService {
    @Autowired
    private UserMapper userMapper;;

    @Override
    public PageInfo<User> getAllUsers(Integer page, Integer count) {
            PageHelper.startPage(page, count);
            List<User> UserList = userMapper.getAllUsers();
            // 封装文章统计数据
            for (int i = 0; i < UserList.size(); i++) {
                User user = UserList.get(i);
//                Statistic statistic = statisticMapper.selectStatisticWithArticleId(article.getId());
//                article.setHits(statistic.getHits());
//                article.setCommentsNum(statistic.getCommentsNum());
            }
            PageInfo<User> pageInfo=new PageInfo<>(UserList);
            return pageInfo;
        }

    @Override
    public void deleteUserById(int id) {
        userMapper.deleteUserById(id);
    }

    @Override
    public User selectUserById(int id) {
        // 根据id查询单个文章详情，并使用Redis进行缓存管理
        User user = null;
        user = userMapper.selectUserById(id);
           return user;
    }


}

